package com.application.outdoor.InvoikeServices;

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.util.Log;

import com.application.Network.Protocol;

public class CayThaoLuanInvoike extends BaseInvoike {
	
	public CayThaoLuanInvoike(){
		super();
		url+="/CayThaoLuanServlet";
	}
	public  String getSubject(String nguoiDung) throws Exception{
		String rs="";
		ArrayList<NameValuePair> params=new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair(Protocol.CMD, Protocol.LAY_DANH_SACH_CAY));
		params.add(new BasicNameValuePair(Protocol.NGUOI_DUNG, nguoiDung));		
		rs=post(url, params);
		return rs;
	}
	public  String getCay(int idCay) throws Exception{
		String rs="";
		ArrayList<NameValuePair> params=new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair(Protocol.CMD, Protocol.LAY_CAY));
		params.add(new BasicNameValuePair(Protocol.ID, idCay+""));		
		rs=post(url, params);
		return rs;
	}
	public  String taoCayMoi(int idNhom, String nguoiTao, String noiDung) throws Exception{
		String rs="";
		ArrayList<NameValuePair> params=new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair(Protocol.CMD, Protocol.TAO_CAY));
		params.add(new BasicNameValuePair(Protocol.NGUOI_DUNG, nguoiTao));
		params.add(new BasicNameValuePair(Protocol.ID_NHOM, idNhom+""));
		params.add(new BasicNameValuePair(Protocol.NOI_DUNG, noiDung));
		
		rs=post(url, params);
		return rs;
	}
	public  String themNode(int idNodeCha, int idCay, String nguoiTao,String noiDung, String ghiChu) throws Exception{
		Log.d(Protocol.TAG,"CayThaoLuanInvoike.themNode"+idNodeCha+" "+idCay+" "+nguoiTao);
		String rs="";
		ArrayList<NameValuePair>params=new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair(Protocol.ID, idNodeCha+""));
		params.add(new BasicNameValuePair(Protocol.ID_CAY, idCay+""));
		params.add(new BasicNameValuePair(Protocol.NGUOI_DUNG, nguoiTao));
		params.add(new BasicNameValuePair(Protocol.NOI_DUNG, noiDung));
		params.add(new BasicNameValuePair(Protocol.GHI_CHU, ghiChu));
		params.add(new BasicNameValuePair(Protocol.CMD, Protocol.THEM_NODE));
		rs=post(url, params);
		return rs;
			
	}
	public  String capNhatNode(int idNode, int idCay,String noiDung, String ghiChu, String nguoiDung) throws Exception{
		String rs="";
		ArrayList<NameValuePair>params=new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair(Protocol.ID, idNode+""));
		params.add(new BasicNameValuePair(Protocol.ID_CAY, idCay+""));
		params.add(new BasicNameValuePair(Protocol.NOI_DUNG, noiDung));
		params.add(new BasicNameValuePair(Protocol.GHI_CHU, ghiChu));
		params.add(new BasicNameValuePair(Protocol.CMD, Protocol.CAP_NHAT_NODE));
		params.add(new BasicNameValuePair(Protocol.NGUOI_DUNG, nguoiDung));
		rs=post(url, params);
		return rs;
			
	}
	public  String xoaNode(int idNodeCha, int idCay,String nguoiDung) throws Exception{
		String rs="";
		ArrayList<NameValuePair>params=new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair(Protocol.ID, idNodeCha+""));
		params.add(new BasicNameValuePair(Protocol.ID_CAY, idCay+""));
		params.add(new BasicNameValuePair(Protocol.CMD, Protocol.XOA_NODE));
		params.add(new BasicNameValuePair(Protocol.NGUOI_DUNG, nguoiDung));
		rs=post(url, params);
		return rs;
			
	}
	public String getThongTinCay(int idCay) throws Exception{
		String rs="";
		ArrayList<NameValuePair> params=new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair(Protocol.CMD, Protocol.THONG_TIN));
		params.add(new BasicNameValuePair(Protocol.ID_CAY, idCay+""));		
		rs=post(url, params);
		return rs;
	}
	public void moiVaoThaoLuan(final String nguoiGui,final String nguoiNhan,final int idCay, final int idNhom){
		Thread t=new Thread(new Runnable() {
			
			@Override
			public void run() {
				try{
					Log.d(Protocol.TAG, "CayThaoLuanInvoike.moiVaoThaoLuan");
					ArrayList<NameValuePair> params=new ArrayList<NameValuePair>();
					params.add(new BasicNameValuePair(Protocol.CMD, Protocol.MOI_VAO_THAO_LUAN));
					params.add(new BasicNameValuePair(Protocol.NGUOI_GUI, nguoiGui));
					params.add(new BasicNameValuePair(Protocol.NGUOI_NHAN, nguoiNhan));
					params.add(new BasicNameValuePair(Protocol.ID_NHOM, idNhom+""));
					params.add(new BasicNameValuePair(Protocol.ID_CAY, idCay+""));
					post(url, params);
					
				}catch (Exception e) {
					Log.e(Protocol.TAG, "CayThaoLuanInvoike.moiVaoThaoLuan"+e);
				}
			}
		});
		t.run();		
	}
}
